$(document).ready(function()
{
	var p=0;
  var q=0;
	$("#username").blur(function()
  {	
     var username = $("#username").val();
	   for(var i=1;i<=localStorage.length;i++)
    {
				var preuser=localStorage.getItem(i);
				preuser=JSON.parse(preuser);
				if(preuser.username==username)
		    {
					$("#ifname").text("确认过眼神，是老用户");
					$("#ifname").css({"font-size":"20px","color":"green","position":"absolute"});
					p=1;
					return;
		    }
				else
				{
					p=0;
					continue;
				}
		}
		$("#ifname").text("会员里没这名");
		$("#ifname").css({"font-size":"20px","color":"red","position":"absolute"});
	  return;
  });
  
  
  $("#userpassword").blur(function()
  {
		var m=0;
		var username = $("#username").val();
		for(var i=1;i<=localStorage.length;i++)
		{
				var preuser=localStorage.getItem(i);
				preuser=JSON.parse(preuser);
				if(preuser.username==username)
				{
					m=1;
					break;
				}
		}
		if(m==0)
		{
			$("#ifpassword").text("上面输入的有问题");
			$("#ifpassword").css({"font-size":"20px","color":"red","position":"absolute"});
			return;
		}
		var userpassword = $("#userpassword").val();
			if(preuser.userpassword==userpassword)
			{
				$("#ifpassword").text("密码正确！！！");
				$("#ifpassword").css({"font-size":"20px","color":"green","position":"absolute"});
				q=1;
				return;
			}
			else
			{
				$("#ifpassword").text("密码错误！！！");
				$("#ifpassword").css({"font-size":"20px","color":"red","position":"absolute"});
				q=0;
				return;
			}
	});
	
	$("#login").click(function()
  {		
		if(q==0||p==0)
		{
			alert("您没弄完呢");
			return;
		}
		if (!window.localStorage) 
	  {
					alert("localstorage好像不能用啊......");
					return;
	  } 
		else 
		{
				var date = new Date();
        var currentTime = date.toLocaleString();
				var username = $("#username").val();
				for(var i=1;i<=localStorage.length;i++)
				{
						var preuser=localStorage.getItem(i);
						preuser=JSON.parse(preuser);
						if(preuser.username==username)
						{
							 break;
						}
				}
				var loguser=
						{
						username:username,
						useremail:preuser.useremail,
						userpassword:preuser.userpassword,
						userregistertime:preuser.userregistertime,
						userlogintime:currentTime,
					  }
				loguser=JSON.stringify(loguser);
				localStorage.setItem(i+1,loguser);
				
				for(var j=1;j<=3;j++)
				{
					alert("得嘞您，距离登录成功还有"+(4-j)+"秒自动跳转");
					setTimeout(1000);
				}
				window.open("success.html");
				window.close("login.html");
     }
  });
});
  
		
		